$(function() {
	$('#vue_vm_list div').hide();
	
	findBySubjectRoomId(getLoginedUser().subjectRoomId);
});

function findBySubjectRoomId(subjectRoomId) {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();

	find_basic_by_json(path+'/elderBedRecord/findBySubjectRoomId', {subjectRoomId: subjectRoomId}, function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getChepingUrl:function(elderId, elderName, elderCardId) {
					return getChepingUrl(elderId, elderName, elderCardId);
				}
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

function handleBatch() {
	var itemIdStr = '';
	var itemIdArray = [];
	
	$('ul').each(function() {
		if($(this).find('.magic-checkbox').is(':checked')) {
			var itemId = $(this).find('.magic-checkbox').attr('id');
			itemIdStr += (itemIdStr==''? itemId: ','+itemId);
			itemIdArray.push(itemId);
		}
	});
	
	if(itemIdArray.length == 0) {
		alert('请先勾选所要办理的项');
		return;
	}
	
	if(confirm('确实要办理所选项吗？')) {
		openWaiting('正在办理');
		
		var dataStr = JSON.stringify({ids:itemIdArray});
		
		$.post(path+'/elderBedRecord/handleBedRecord', {data: dataStr}, function(response) {
			closeWaiting();
			
			if(response.code=='200') {
				$('ul').each(function() {
					if($(this).find('.magic-checkbox').is(':checked')) {
						$(this).remove();
					}
				});
				
				alert('办理成功');
			}else {
				alert(response.info);
			}
			
			console.log(response);
		});
		
		closeWaiting();
	}
};

function deleteBatch() {
	deleteBatch_basic(path+'/cgSendOrder/deleteBatch');
}
